package com.example.chessapp;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.FloatEvaluator;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ConfigActivity extends AppCompatActivity {

    public static final String TAG = "ConfigActivity";
    float dollar2;
    float euro2;
    float won2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);

        Intent intent=getIntent();
        dollar2=intent.getFloatExtra("dollarRate",0.0f);
        euro2=intent.getFloatExtra("euroRate",0.0f);
        won2=intent.getFloatExtra("wonRate",0.0f);

        Button bt = findViewById(R.id.button4);

        TextView drtext=findViewById(R.id.dr);
        String dr2 = String.valueOf(dollar2);
        drtext.setText(dr2);

        TextView ertext=findViewById(R.id.er);
        String er2 = String.valueOf(euro2);
        ertext.setText(er2);

        TextView wrtext=findViewById(R.id.wr);
        String wr2 = String.valueOf(won2);
        wrtext.setText(wr2);


    }

     public void CtoR(View v){
        TextView drtext=findViewById(R.id.dr);
        TextView ertext=findViewById(R.id.er);
        TextView wrtext=findViewById(R.id.wr);
        //判断是否为空
         float dollar= Float.parseFloat(drtext.getText().toString());
         float euro=Float.parseFloat(ertext.getText().toString());
         float won=Float.parseFloat(wrtext.getText().toString());

         Intent intent = getIntent();
         Bundle bdl = new Bundle();
         bdl.putFloat("dollarRate",dollar);
         bdl.putFloat("euroRate",euro);
         bdl.putFloat("wonRate",won);
         intent.putExtras(bdl);
         setResult(2,intent);

         SharedPreferences sp = getSharedPreferences("myrate",ConfigActivity.MODE_PRIVATE);
         SharedPreferences.Editor editor = sp.edit();
         editor.putFloat("dollar_r",dollar);
         editor.putFloat("euro_r",euro);
         editor.putFloat("won_r",won);
         editor.apply();

         finish();

//        Intent rate=new Intent(this,RateActivity.class);
//        rate.putExtra("dollarRate",dollar);
//        rate.putExtra("euroRate",euro);
//        rate.putExtra("wonRate",won);
//        startActivity(rate);
    }

}